package com.sda.huoshui.dialog

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.widget.ImageView
import android.widget.TextView

import com.flyco.dialog.widget.base.BaseDialog
import com.sda.huoshui.R
import com.sda.huoshui.view.clickDelay

/**
 * 基础提示窗，可设置标题，提示语，按钮监听
 */
class MyBaseDialog(context: Context) : BaseDialog<MyBaseDialog>(context) {

    private var onDialogClickListener: OnDialogClickListener?= null
    private val customView: View = LayoutInflater.from(context).inflate(R.layout.dialog_mybase, null)

    override fun onCreateView(): View {
        widthScale(0.85f)
        return customView
    }

    fun setOnDialogClickListener(onDialogClickListener: OnDialogClickListener): MyBaseDialog {
        this.onDialogClickListener = onDialogClickListener
        return this
    }

    fun setMessageText(text: String): MyBaseDialog {
        customView.findViewById<TextView>(R.id.tvMessage).text = text
        return this
    }

    fun setRightText(text: String): MyBaseDialog {
        customView.findViewById<TextView>(R.id.tvRight).text = text
        return this
    }

    fun setTitleText(text: String): MyBaseDialog {
        customView.findViewById<TextView>(R.id.tvTitle).text = text
        return this
    }

    fun setLeftText(text: String): MyBaseDialog {
        customView.findViewById<TextView>(R.id.tvLeft).text = text
        return this
    }

    fun setMeddleVisibility (isShow:Boolean): MyBaseDialog {
        if (isShow){
            customView.findViewById<TextView>(R.id.tvMiddle).visibility = View.VISIBLE
        }else{
            customView.findViewById<TextView>(R.id.tvMiddle) .visibility = View.GONE
        }
        return this
    }

    fun setLeftAndRightVisibility (isShow:Boolean): MyBaseDialog {
        if (isShow){
            customView.findViewById<TextView>(R.id.llLeftAndRight).visibility = View.VISIBLE
        }else{
            customView.findViewById<TextView>(R.id.llLeftAndRight) .visibility = View.GONE
        }
        return this
    }
    override fun setUiBeforShow() {
        customView.findViewById<TextView>(R.id.tvLeft).clickDelay { dismiss()
            onDialogClickListener?.onCancle()
        }
        customView.findViewById<TextView>(R.id.tvMiddle).clickDelay {dismiss()
            onDialogClickListener?.onClick() }
        customView.findViewById<TextView>(R.id.tvRight).clickDelay {dismiss()
            onDialogClickListener?.onClick() }
    }

    interface OnDialogClickListener {
        fun onClick()
        fun onCancle()
    }

}
